<?php
namespace app\bbs\controller;
class Api extends Base
{
    //编辑器上传图片
    public function upload(){
        if(is_post()){
            $rs = m('Attachment','xcom')->upimg();
            if($rs){
                $d = [
                    'status' => 0,
                    'url' => $rs,
                ];
                exit(json_encode($d));
            }else{
                err(m('Attachment','xcom')->getError());
            }
        }
    }

    //上传图片
   public function upimg(){
       if(is_post()){
           $rs = m('Attachment','xcom')->upimg();
           if($rs){
                suc(['url'=>$rs]);
           }else{
                err(m('Attachment','xcom')->getError());
           }
       }
   }

    //qq登录
    public function qq(){
        $callbackUrl = url('qq/reback');
        $qqOAuth = new \Yurun\OAuthLogin\QQ\OAuth2(c('api.qq_connect_appid'), c('api.qq_connect_appkey'), $callbackUrl);

        // 获取登录授权跳转页地址
        $url = $qqOAuth->getAuthUrl();
        // 存储sdk自动生成的state，回调处理时候要验证
        cookie('YURUN_QQ_STATE', $qqOAuth->state);
        // 跳转到登录页
        header('location:' . $url);
    }

    //微博登录
    public function weibo(){
        err('暂未开放微博绑定');
    }
}
